<%@ page contentType="text/html;charset=UTF-8" %>

<!DOCTYPE html>
<html>
<head>
	<title>附件库注册信息列表</title>
	<%@ include file="/common/import.jsp" %>

	<script>
	$(function(){
			$('#attaRegisterList').datagrid({
				title:'注册信息列表',
				iconCls:'icon-ok',
				url:'${ctx }/attachment/register/list!data.action',
				nowrap: false,
				striped: true,
				collapsible:false,				
				fitColumns: true,
				singleSelect:true,
				rownumbers:true,
				remoteSort: false,
				pagination: false,
				idField:'rid',
				columns:[[
					{field:'regEname',title:'注册英文标示',width:100,sortable:true},
					{field:'regCname',title:'注册中文名称',width:100,sortable:true},
					{field:'picTotalNum',title:'上传数量设置',width:100,sortable:true},
					{field:'alloweTypes',title:'允许的文件类型',width:100,sortable:true},
					{field:'maxLength',title:'文件大小限制(KB)',width:100,sortable:true},
					/*{field:'writeControlLevel',title:'写权限级别',width:100,sortable:true,
					  formatter:function(val){
							if( val=='1'){return '不需要登录用';}
							else if(val == '2'){ return '登录即可以用';}
							else if(val == '3'){return '登录必须有相应权限才能用';}
							else{ return '';}
						}
					},
					{field:'writeKey',title:'写权限key',width:50,sortable:true},
					{field:'readControlLevel',title:'读权限级别',width:100,sortable:true,
					   formatter:function(val){
							if( val=='1'){return '不需要登录用';}
							else if(val == '2'){ return '登录即可以用';}
							else if(val == '3'){return '登录必须有相应权限才能用';}
							else{ return '';}
						}
					},
					{field:'readKey',title:'读权限key',width:50,sortable:true},
					{field:'attaSort',title:'注册类型',width:50,sortable:true,
					     formatter:function(val){
							if( val=='0'){return '附件';}
							else if(val == '1'){ return '图片';}
						}
					},*/
					{field:'itemValue',title:'操作',width:100,sortable:true,
					    formatter:function(val,rec){						
							var temp1 = "<a href=\"javascript:void(0)\" onclick=\"editAttaReg('"
													+ rec.rid
													+ "')\" title='修改'>修改</a>";
							var temp2 = "<a href=\"javascript:void(0)\" onclick=\"deleteAttaReg('"
													+ rec.rid
													+ "')\" title='删除'>删除</a>";
                            var view = temp1 +" "+ temp2;
                            return view;
						}
					}					
				]],
				toolbar:[{
					text:'注册',
					iconCls:'icon-add',
					handler:function(){
						addAttaReg();
					}
				}
				,'-',{
					text:'刷新',
					iconCls:'icon-reload',
					handler:function(){
						attaRegReload();
					}
				}
				
				]
			})
		});
		
	      //取得数据
		  function getSelected(){
		  	var rec = $('#attaRegisterList').datagrid('getSelected');
		  	if(rec){
		  		return rec;
		  	}else{
		  		$.messager.alert('提示',"请选择需要操作记录!", 'info');
		  		return null;
		  	}
		  }	
		
		function colseAdd(){
			$('#saveDiv').window('close');
		}
		
		function attaRegReload(){
		    $('#attaRegisterList').datagrid('reload');
		}
		
		// 增加
		function addAttaReg(){
			$('#saveFrame').html('');			
			var url = '${ctx}/attachment/register/add.action';				
			$('#saveFrame').attr("title",'');
			$('#saveFrame').attr("src",url);
			$('#saveDiv').window('open');	
		}
		
		
		//修改
		function editAttaReg(){
		 var node = getSelected();		
			if (node){	
				var url = '${ctx}/attachment/register/edit.action?id='+node.rid;
				$('#saveFrame').attr("title",node.regEname);
				$('#saveFrame').attr("src",url);
				$('#saveDiv').window('open');
			}
		}
		
		// 删除
		function deleteAttaReg(){					
			var node = getSelected();	
			if(node){
		    	$.messager.confirm('确认','您确定要删除:<font color=red>'+node.regEname+'</font> ？',function(r){
			    	if(r){
						$.ajax({
							type: "post",
							url: "${ctx}/attachment/register/del.action?id="+node.rid,
							success: function(data, textStatus){
								var result = jQuery.parseJSON(data);
	    						if(result.flag=='T'){
									$.messager.alert('结果', '操作成功', 'info',function(){
										//$('#attaRegisterList').datagrid('remove', node.rid);
										//window.location.reload();
										$('#attaRegisterList').datagrid('reload');
									});	
	    						}else{
	    							$.messager.alert('结果', '操作失败，请重试', 'error');	
	    						}
							},
							error: function(messg){
								$.messager.alert('错误提示', '操作失败:'+messg.responseText, 'error');
							}
						});
			        }
		       });		             		
		    }	
		}
		
	</script>
</head>
<body>

	<table id="attaRegisterList"></table>

	<!-- 增加、修改窗口 -->
	<div id="saveDiv" class="easyui-window" title="附件库注册" style="padding:5px;width: 800px;height:430px;" 	
    	iconCls="icon-edit" closed="true" maximizable="false" minimizable="false" collapsible="false">
   		<iframe frameborder="0"  id="saveFrame" height="100%" width="100%" scrolling="No" frameborder="0" ></iframe>
    </div>

</body>
</html>